<?php

	include("common.php");
	
	$result = mysql_query("SELECT * FROM `197_teachers` ORDER BY `teacher_id` ASC");
	$teachers = array();
	while($row = mysql_fetch_assoc($result)){
		array_push($teachers, $row);
	}
	
?>
<?php include("header.php"); ?>
<h1>修改／刪除教師</h1>
<div id="delete-teacher-dialog">
	<p>確定刪除？</p>
</div>
<script type="text/javascript" defer="defer">
	$("#delete-teacher-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "刪除帳號",
		modal: true,
		draggable: false,
		resizable: false
	});
	function showConfirm(teacher_id){
		$("#delete-teacher-dialog").dialog("option", "buttons", {"確定": function(){ $(this).dialog("close"); deleteTeacher(teacher_id); }, "取消": function(){ $(this).dialog("close"); }
		}).dialog("open");
	}
	function deleteTeacher(teacher_id){
		$("#delete-teacher-dialog").dialog("option", "buttons", { "關閉": function(){ location.reload(); } });
		$("#delete-teacher-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#delete-teacher-dialog").dialog("open");
		$("#delete-teacher-dialog").load("teacherDelete.php?teacher_id=" + teacher_id + "&ajax=true");
	}
</script>
<ul>
	<?php foreach($teachers as $row){ ?>
		<li><?php echo $row['name']; ?>（<?php echo $row['username']; ?>） - [ <a href="teacherEdit.php?teacher_id=<?php echo $row['teacher_id']; ?>">修改</a>｜<a href="teacherDelete.php?user_id=<?php echo $row['teacher_id']; ?>" onclick="showConfirm(<?php echo $row['teacher_id']; ?>); return false;">刪除</a> ]</li>
	<?php } ?>
</ul>
<p><a href="teacherAdd.php">新增</a></p>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>